import Vue from 'vue'
import Router from 'vue-router'

const _import = require('./_import_vue')

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/** note: Submenu only appear when children.length>=1
 *
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [{
  path: '/redirect',
  component: Layout,
  hidden: true,
  children: [{
    path: '/redirect/:path*',
    component: () =>
                import('@/views/redirect/index')
  }]
},
{
  path: '/login',
  component: () =>
            import('@/views/login/index'),
  hidden: true
},
{
  path: '/auth-redirect',
  component: () =>
            import('@/views/login/authredirect'),
  hidden: true
},
{
  path: '/404',
  component: () =>
            import('@/views/errorPage/404'),
  hidden: true
},
{
  path: '/401',
  component: () =>
            import('@/views/errorPage/401'),
  hidden: true
},
{
  path: '',
  component: Layout,
  redirect: 'dashboard',
  children: [{
    path: 'dashboard',
    component: () =>
                    import('@/views/dashboard/index'),
    name: 'Dashboard',
    meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
  },
  {
    path: '/device',
    component: () =>
                    import('@/views/fire/site/deviceManage'),
    name: 'device',
    meta: { title: '传感器管理', icon: 'dashboard', noCache: true },
    hidden: true
  },
  {
    path: 'info',
    component: () =>
                    import('@/views/sys/user/info'),
    name: 'userInfo',
    hidden: true,
    meta: { title: '用户信息', icon: 'dashboard', noCache: true }
  },
  {
    path: 'change/password',
    component: () =>
                    import('@/views/sys/user/changePassword'),
    name: 'changePassword',
    hidden: true,
    meta: { title: '修改密码', icon: 'dashboard', noCache: true }
  },
  {
    path: '/asset/index',
    component: () =>
              import('@/views/fire/asset/index'),
    name: 'assetIndex',
    hidden: true,
    meta: { title: '设施管理', icon: 'dashboard', noCache: true }
  },
  {
    path: '/proprietor/asset/outroom',
    component: () =>
      import('@/views/fire/asset/facility/index'),
    name: 'outroom',
    hidden: true,
    meta: { title: '室外消防给水资产列表', icon: 'dashboard', noCache: true }
  },
  {
    path: '/proprietor/asset/inroom',
    component: () =>
      import('@/views/fire/asset/facility/index'),
    name: 'inroom',
    hidden: true,
    meta: { title: '室内消火栓系统资产列表', icon: 'dashboard', noCache: true }
  },
  {
    path: '/proprietor/asset/autospring',
    component: () =>
      import('@/views/fire/asset/facility/index'),
    name: 'autospring',
    hidden: true,
    meta: { title: '自动喷水灭火系统资产列表', icon: 'dashboard', noCache: true }
  },
  {
    path: '/proprietor/asset/gasfire',
    component: () =>
      import('@/views/fire/asset/facility/index'),
    name: 'gasfire',
    hidden: true,
    meta: { title: '气体灭火资产列表', icon: 'dashboard', noCache: true }
  },
  {
    path: '/proprietor/asset/foamfire',
    component: () =>
      import('@/views/fire/asset/facility/index'),
    name: 'foamfire',
    hidden: true,
    meta: { title: '泡沫系统资产列表', icon: 'dashboard', noCache: true }
  },
  {
    path: '/proprietor/asset/autoalarm',
    component: () =>
      import('@/views/fire/asset/facility/index'),
    name: 'autoalarm',
    hidden: true,
    meta: { title: '火灾自动报警系统资产列表', icon: 'dashboard', noCache: true }
  },
  {
    path: '/proprietor/asset/ejectsmoke',
    component: () =>
      import('@/views/fire/asset/facility/index'),
    name: 'ejectsmoke',
    hidden: true,
    meta: { title: '排烟系统资产列表', icon: 'dashboard', noCache: true }
  },
  {
    path: '/proprietor/asset/smokeprevention',
    component: () =>
      import('@/views/fire/asset/facility/index'),
    name: 'smokeprevention',
    hidden: true,
    meta: { title: '烟防系统资产列表', icon: 'dashboard', noCache: true }
  },
  {
    path: '/proprietor/asset/keypart',
    component: () =>
      import('@/views/fire/asset/facility/index'),
    name: 'keypart',
    hidden: true,
    meta: { title: '重点部位系统资产列表', icon: 'dashboard', noCache: true }
  },
  {
    path: '/proprietor/asset/other',
    component: () =>
      import('@/views/fire/asset/facility/index'),
    name: 'other',
    hidden: true,
    meta: { title: '其他系统资产列表', icon: 'dashboard', noCache: true }
  },
  {
    path: '/asset/measure',
    component: () =>
              import('@/views/fire/asset/measure'),
    name: 'measure',
    hidden: true,
    meta: { title: '测量', icon: 'dashboard', noCache: true }
  },
  {
    path: '/site/reportInfo',
    component: () =>
        import('@/views/fire/site/reportInfo'),
    name: 'ReportInformation',
    hidden: true,
    meta: { title: '信息填报', icon: 'dashboard', noCache: true }
  }
    /* {
                path: '/proprietor/monitor/electricity',
                component: () =>
                    import ('@/views/fire/proprietor/monitor/water'),
                name: 'electricity',
                hidden: true,
                meta: { title: '电力监控', icon: 'dashboard', noCache: true }
            },
            {
                path: '/proprietor/monitor/water',
                component: () =>
                    import ('@/views/fire/proprietor/monitor/water'),
                name: 'water',
                hidden: true,
                meta: { title: '水务监控', icon: 'dashboard', noCache: true }
            },
            {
                path: '/proprietor/monitor/gas',
                component: () =>
                    import ('@/views/fire/proprietor/monitor/water'),
                name: 'gas',
                hidden: true,
                meta: { title: '燃气监控', icon: 'dashboard', noCache: true }
            },
            {
                path: '/proprietor/monitor/fire',
                component: () =>
                    import ('@/views/fire/proprietor/monitor/water'),
                name: 'fire',
                hidden: true,
                meta: { title: '火灾监控', icon: 'dashboard', noCache: true }
            },
            {
                path: '/proprietor/monitor/video',
                component: () =>
                    import ('@/views/fire/proprietor/monitor/water'),
                name: 'video',
                hidden: true,
                meta: { title: '视频监控', icon: 'dashboard', noCache: true }
            }*/
  ]
}
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

/**
 * 处理路由信息
 *
 * @param routerMap
 */
export function processRouter(routerMap) {
  const newRouters = routerMap.filter(router => {
    const component = router.component
    try {
      router.name = router.path
      if (component) {
        if (component === 'Layout') {
          router.component = Layout
        } else {
          router.component = _import(component)
        }
      } else {
        router.component = undefined
      }
    } catch (e) {
      router.component = () =>
                import('@/views/errorPage/404')
    }
    if (router.children && router.children.length) {
      router.children = processRouter(router.children)
    }
    return true
  })
  return newRouters
}
